package com.ayu.scalalearn.chapter07

/**
  * @Author 徐林玉
  * @Description Test04List
  * @Date 2022/8/3 13:56
  * @Version 1.0
  */
object Test04List {

  def main(args: Array[String]): Unit = {

    //1、创建一个list
    val list = List(23, 65, 87)


    //2、访问元素
    println(list(1))

    list.foreach(print)


    //3、添加元素
    val newList = 10 +: list

    val newList2 = newList :+ 20

    println("=====================")

    println(list)

    println(newList)

    println(newList2)

    println("==================")

    val list4 = list.::(51)
    println(list4)

    val list5 = Nil.::(13)
    println(list5)

    val list6 = 73 :: 32 :: Nil
    val list7 = 17 :: 28 :: 59 :: 16 :: Nil
    println(list7)

    // 4. 合并列表
    //List(List(73, 32), 17, 28, 59, 16)
    val list8 = list6 :: list7
    println(list8)


    //List(73, 32, 17, 28, 59, 16)
    val list9 = list6 ::: list7
    println(list9)


    //List(73, 32, 17, 28, 59, 16)
    val list10 = list6 ++ list7
    println(list10)


  }


}
